from ronglian_sms_sdk import SmsSDK
import json
accId = '8a216da878005a800178acc7cc2e3f86'
accToken = '05441d79a6e343c79dc3205ffc953edf'
appId = '8a216da878005a800178acc7cd393f8c'


# 示例代码
# def send_message():
#     sdk = SmsSDK(accId, accToken, appId)
#     tid = '1'  # 测试模板id
#     mobile = '15907592071'
#     datas = ('123456', '5')  # 验证码，有效时间
#     resp = sdk.sendMessage(tid, mobile, datas)
#     print(resp)


# send_message()


# 单例
class CCP(object):
    def __new__(cls, *args, **kwargs):
        if not hasattr(cls, '_instance'):  # 如果这个类没有这个单例，则初始化
            cls._instance = super(CCP, cls).__new__(cls, *args, **kwargs)  # 调用cls的父类object的__new__方法，返回一个类的实例_instance
            cls._instance.sdk = SmsSDK(accId, accToken, appId)  # 给单例_instance绑定一个变量
        return cls._instance

    def send_msg(self, tid, mobile, datas):
        result = self.sdk.sendMessage(tid, mobile, datas)
        jsonData = json.loads(result)
        if jsonData.get('statusCode') == '000000':
            return 0
        else:
            return -1


if __name__ == '__main__':
    CCP().send_msg(1, '15907592071', ('123456', '5'))
